package com.gw.vip.server.config;

import com.gw.vip.common.exception.ServiceException;
import com.gw.vip.server.bo.MailSenderInfo;
import com.gw.vip.server.constants.SysArgKey;
import com.gw.vip.server.service.dao_service.SysArgService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author GW
 * @description 邮件发送者信息
 * @since 2022-09-21
 */
@Configuration
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MailSenderInfoConfig {

    private final SysArgService sysArgService;

    @Bean
    public MailSenderInfo mailSenderInfo(){
        //获取邮件发送者信息
        MailSenderInfo mailSenderInfo = sysArgService.getObject(SysArgKey.MAIL_SENDER_INFO, MailSenderInfo.class);
        if (mailSenderInfo==null){
            log.error("邮件发送者不存在！");
            throw new ServiceException("邮件发送者不存在!");
        }
        return mailSenderInfo;
    }
}
